package dao.impl;

import dao.BaseDao;
import dao.UserDao;
import pojo.User;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User queryUserByUsernaem(String username) {
        String sql = "select `id`,`username`,`password`,`email` from book where username = ?";
        return queryForOne(User.class, sql, username);
    }


    @Override
    public int saveUser(User user) {
        String sql = "insert into book(`username`,`password`,`email`) values(?,?,?)";
        return update(sql, user.getUsername(),user.getPassword(),user.getEmail());
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from book where username = ? and password = ?";
        return queryForOne(User.class, sql, username,password);
    }

    @Override
    public List<User> quertByUsersinglename(String username) {
        String sql = "select * from book where username like '%" + username +"%'";;
        return queryForList(User.class,sql);
    }
}
